/**
* @Description:  增加标签的方法
* @author maoze@hsyuntai.com
* @date 2018/5/14 10:44
* @params No such property: code for class: Script1
* @return
* Modified By:
*/



/*
*  list 的子元素是一个{value：XX,text:XXX}
* */
function addLableByList(list,name) {
    var checkedList = new Array();
    // 去除重复的value
    for(var cell in list){
        var flag = true;
            $(".note_lable[name=" +name +"]").each(function (index,value) {
                if(list[cell].value == $(value).attr('value')){
                    flag =false;
                }
            });
       if(flag){
           checkedList.push(list[cell]);
       }
    }
    $(".note[name='" + name+"']").removeClass('error');
    $("#" +name +"-error").css("display","none");
    // $('.note[name=' + name+']').children().remove();
    var str = "";
    for(var index in checkedList){
        str += '<div class="note_lable" name="' +name +'" value="' + checkedList[index].value+'">\n' +
            '<lable>' +checkedList[index].text +'</lable>\n' +
            '<div  onclick="$(this).parent().remove()">X</div>\n' +
            '<div  class="note_mind"></div>\n' +
            '</div>'
    }
    $('.note[name=' + name).append(str);
}

function htmlLableByList(list,name) {
    var checkedList = list;
    $(".note[name='" + name+"']").removeClass('error');
    $("#" +name +"-error").css("display","none");
    var str = "";
    for(var index in checkedList){
        str += '<div class="note_lable" name="' +name +'" value="' + checkedList[index].value+'">\n' +
            '<lable>' +checkedList[index].text +'</lable>\n' +
            '<div  onclick="$(this).parent().remove()">X</div>\n' +
            '<div  class="note_mind"></div>\n' +
            '</div>'
    }
    $('.note[name=' + name).html(str);
}

function getlableNote(name,error) {
    var list = []
   $(".note_lable[name=" +name +"]").each(function (index,value) {
       list.push($(value).attr('value'));
   });
    if(error) // 为必选
    {
        if(list.length == 0){
            $(".note[name='" + name+"']").addClass("error");
            $("#" +name +"-error").css("display","block");
        }
    }
    return list;
}

function getLabelNoteStr(name, error) {
    var result = '';
    $(".note_lable[name=" +name +"]").each(function (index,value) {
        result = result + $(value).attr('value') + ',';
    });
    if(error) {
        if(!result || result == ''){
            $(".note[name='" + name+"']").addClass("error");
            $("#" +name +"-error").css("display","block");
        }
    }
    return result == '' ? '' : result.substring(0, result.length - 1);
}


function addNote(id,name,max) {
    var noteStr = $.trim($("#"+id).val());
    var flag = true;
    if(max != null && $(".note_lable[name=" +name +"]").length == max){
        toastr.error("标签不能超过"+max+"个");
        return;
    }
    if($(".note_lable[name=" +name +"]").length > 0)
    $(".note_lable[name="+name+"]").each(function (index,value) {
        if($(value).attr('value') == noteStr){
            flag =false;
        }
    });
    if(!flag){
        toastr.error("名称已经存在");
        return;
    }
    var str = "";
        str += '<div class="note_lable" name="' +name +'" value="' + noteStr+'">\n' +
            '<lable>' +noteStr +'</lable>\n' +
            '<div  onclick="$(this).parent().remove()">X</div>\n' +
            '<div  class="note_mind"></div>\n' +
            '</div>';
    $('.note[name=' + name).append(str);
}